import { createStore } from 'vuex'

export default createStore({
  state: {
    SmartNeroUser: JSON.parse(localStorage.getItem('SmartNeroUser')) || null
  },
  getters: {
    getSmartNeroUser: (state) => state.SmartNeroUser, // 确保有这个getter
    getUserDisplayName: (state) => {
      if (!state.SmartNeroUser) return '游客'
      return state.SmartNeroUser.nickname || state.SmartNeroUser.username || '用户'
    }
  },
  mutations: {
    setSmartNeroUser(state, user) {
      state.SmartNeroUser = user
      localStorage.setItem('SmartNeroUser', JSON.stringify(user))
    },
    clearUser(state) {
      state.SmartNeroUser = null
      localStorage.removeItem('SmartNeroUser')
    }
  }
})
